import Vue from 'vue'
import Vuex from 'vuex'
import { getItem,setItem } from "@/utils/storage";

Vue.use(Vuex)
const TOKEN_KEY = 'TOUTIAO_USER'
export default new Vuex.Store({
	state: {
		user:getItem(TOKEN_KEY), //用户信息 token等
	},
	getters: {
	},
	mutations: {
		setUser(state,data){
			state.user = data

			// 为了防止页面刷新丢失 把数据备份到本地存储
			// window.localStorage.setItem(TOKEN_KEY,JSON.stringify(state.user))
			setItem(TOKEN_KEY,state.user)
		}
	},
	actions: {
	},
	modules: {
	}
})
